<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>

	
<title>悦章科技机构平台</title>	

	
<!--内容样式-->
<link rel="stylesheet" href="__PUBLIC__/Home/css/style.css" />

<style>
::-webkit-scrollbar {/*隐藏滚轮*/
	display: block;
}
	::-webkit-scrollbar{
  width:8px;
  height:8px;
  /**/
}
::-webkit-scrollbar-track{
  background: rgb(239, 239, 239);
  border-radius:2px;
}
::-webkit-scrollbar-thumb{
  background: #bfbfbf;
  border-radius:10px;
}
::-webkit-scrollbar-thumb:hover{
  background: #999;
}
::-webkit-scrollbar-corner{
  background: #179a16;
}
</style>
	
	
</head>

<body>

	
	<div class="main">
	
	
		<!--  头部  -->
	<header class="head">
	    <div class="hd-logo">
	        <img src="__PUBLIC__/Home/images/img_logo.png" />
	    </div>
	    <div class="hd-nav">
	        <a href="{:U('Home/Index/Index')}" <if condition="$cur eq '数据统计' || $cur eq '排行榜' || $cur eq '线索列表' || $cur eq '客户列表' || $cur eq '跟进记录'">class="hdn-btn active"<else/>class="hdn-btn"</if>>招生系统</a>
	        <a href="{:U('Home/Educational/classClassification')}" <if condition="$cur eq '班级分类' || $cur eq '班级列表' || $cur eq '学生管理'">class="hdn-btn active"<else/>class="hdn-btn"</if>>教务系统</a>
	        <a href="{:U('Home/Finance/order')}" <if condition="$cur eq '交易管理' || $cur eq '收费管理'">class="hdn-btn active"<else/>class="hdn-btn"</if>>财务系统</a>
	        <a href="{:U('Home/Operate/contentStatistics')}" <if condition="$cur eq '内容统计' || $cur eq '直播课管理' || $cur eq '视频课管理' || $cur eq '面授课管理'">class="hdn-btn active"<else/>class="hdn-btn"</if>>运营系统</a>
	        <a href="{:U('Home/Marketing/groupWork')}" <if condition="$cur eq '课程拼团' || $cur eq '课程秒杀' || $cur eq '优惠券管理'">class="hdn-btn active"<else/>class="hdn-btn"</if>>营销系统</a>
	        <a href="{:U('Home/Purchasing/purchasingAgentList')}" <if condition="$cur eq '代购记录'">class="hdn-btn active"<else/>class="hdn-btn"</if>>课程代购</a>
	        <a href="{:U('Home/Mechanism/setInfo')}" <if condition="$cur eq '师资力量' || $cur eq '意见反馈' || $cur eq '信息设置'">class="hdn-btn active"<else/>class="hdn-btn"</if>>机构管理</a>
	        <div class="divclear"></div>
	    </div>
	    <div class="hd-r">
	        <div class="hdr-tx">
	            <img <if condition="$member['avatar'] neq ''">src="{$member.avatar}"<else/>src="__PUBLIC__/Home/images/imgTX.jpg"</if> />
	        </div>
	        <div class="hdr-mc">湖南多桐教育培训学校，欢迎你</div>
	        <div class="hdr-tc">
	            <a href="{:U('Home/Index/outLogin')}">
	                <img src="__PUBLIC__/Home/images/icon_out.png"/>
	            </a>
	        </div>
	        <div class="divclear"></div>
	    </div>
	    <div class="divclear"></div>
	</header>
		
		
		
		<!--  直播间  -->
		<div class="live-room">
		
			    <!-- {$userSig} -->
			<div class="lr-l">
				
				<div class="lrl-title">
					<div class="lrlt-bt">Photoshop高级进阶课程</div>
					<div class="lrlt-btn" onclick="startLive()">开启直播</div>
					<div class="lrlt-gn">
						<div class="lrltg-box" onclick="startCamera()">
							<img src="__PUBLIC__/Home/images/icon_zbj1.png" />
							<span>打开摄像头</span>
						</div>
						<div class="lrltg-box" onclick="startMicrophone()">
							<img src="__PUBLIC__/Home/images/icon_zbj2.png" />
							<span>打开话筒</span>
						</div>
						<div class="lrltg-box" onclick="startShare()">
							<img src="__PUBLIC__/Home/images/icon_zbj3.png" />
							<span>分享屏幕</span>
						</div>
						<div class="divclear"></div>
					</div>
					<div class="divclear"></div>
				</div>
				
				<div class="lrl-xs">

				</div>
				
				<div class="lrl-hm" id="pusherView">

				</div>
				
			</div>
			
			
			<div class="lr-r">
				
				<div class="lrr-tab">
					<div class="lrrt-btn lt" id="chat">群聊</div>
					<div class="lrrt-btn zx" id="online">在线(<input name="nm" style="border: 0;margin: 0;padding: 0;outline: none;width:10px;background: #bfbfbf">)</div>
					<div class="divclear"></div>
				</div>
				
				<!--群聊-->
				<div class="lrr-lt">
					<p class="lrrl-gg">请使用文明用语，禁止传播低俗、涩情、违法内容。</p>

				</div>
				
				<!--在线-->
				<div class="lrr-zx">


				</div>
				
				<form class="lrr-foot">
					<input type="text" placeholder="说点什么..." class="lrrf-wb" name="xx">
					<div class="lrrf-btn" onclick="sendMsg()">发送</div>
					<div class="divclear"></div>
				</form>
				
			</div>
			
			
			<div class="divclear"></div>
			
			
		</div>
		
		
		
	</div>
	
	
	
</body>
</html>
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer/layer.js"></script>
<script src="/Public/static/live/TRTCSDK/trtc.js"></script>
<script src="/Public/static/live/TIMSDK/tim-js.js"></script>
<script src="/Public/static/live/TWEBLIVE/tweblive.js"></script>
<script>
	var SDKAppId = {$SDKAppID};
	var userId = "{$userID}";
	var userSig = "{$userSig}";
	var roomId = "{$roomID}";
	var pusher = TWebLive.createPusher({userID: userId});
	let shareClient = null;
	let shareStream = null;

    var options = {
        SDKAppID: 1400466140 // 接入时需要将0替换为您的即时通信 IM 应用的 SDKAppID
    };
    // 创建 SDK 实例，`TIM.create()`方法对于同一个 `SDKAppID` 只会返回同一份实例
    var tim = TIM.create(options);
        let onMessageReceived = function (event) {
        // 收到推送的单聊、群聊、群提示、群系统通知的新消息，可通过遍历 event.data 获取消息列表数据并渲染到页面
        // event.name - TIM.EVENT.MESSAGE_RECEIVED
        // event.data - 存储 Message 对象的数组 - [Message]
        console.log(event.data);
        console.log('收到消息----  ' + event.data[0].from + '：' + event.data[0].payload.text);
        if(event.data[0].payload.text !== undefined){
        	var hh='<div class="lrrl-nr"><span style="color:#299cfe;">'+event.data[0].from+'：</span>'+event.data[0].payload.text+'</div>';
        	// $('.lrr-lt').append(event.data[0].from + '：' + event.data[0].payload.text);
        	$('.lrr-lt').append(hh);
        }
        
    };
    tim.on(TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived);


// let promise = tim.getGroupOnlineMemberCount('group1');
// promise.then(function(imResponse) {
//   console.log(imResponse.data.memberCount);
// }).catch(function(imError) {
//   console.warn('getGroupOnlineMemberCount error:', imError); // 获取直播群在线人数失败的相关信息
// });

    

$(document).ready(function(){
        	$('.lrr-zx').hide();
        	$('.zx').removeClass('lrrt-btn-on');
        	$('.lt').addClass('lrrt-btn-on');
        	$('.lrr-lt').show();

    //先登录
    tim.login({userID: userId, userSig: userSig}).then(function (imResponse) {
        if (imResponse.data.actionStatus === 'OK') {
            if (imResponse.data.repeatLogin) {
                console.log('重复登录');
            } else {
                console.log('登录成功');
                tim.on(TIM.EVENT.SDK_READY, function (event) {
                    console.log("ready成功");

				let promisey = tim.getGroupMemberList({ groupID:roomId, count: 30, offset:0 }); // 从0开始拉取30个群成员
				promisey.then(function(imResponse) {
				  console.log(imResponse.data.memberList); // 群成员列表
				  // console.log(imResponse.data.memberList.length);
				  $("input[name='nm']").val(imResponse.data.memberList.length);
				  var zz='';
				  var bb=''
				  for (let groupMember of imResponse.data.memberList) {

				    if (groupMember.muteUntil * 1000  > Date.now()) {
				      console.log(`${groupMember.userID} 禁言中`);
					    zz+='<div class="lrlx-box">';
						zz+='<div class="lrlxb-img">';
						zz+='<img src="__PUBLIC__/Home/images/img2.jpg" />';
						zz+='</div>';
						zz+='<div class="lrlxb-mc">'+groupMember.userID+'</div>';
						zz+='<div class="lrlxb-gb">同意发言</div>';
						zz+='<div class="divclear"></div>';
						zz+='</div>';

						bb+='<div class="lrrz-box">';
						bb+='<div class="lrrzb-img">'
						bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
						bb+='</div>';
						bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
						bb+='<div class="lrrzb-qx" onclick="qxjy()">取消禁言</div>';
						bb+='<div class="divclear"></div>';
						bb+='</div>';
				    } else {
				      console.log(`${groupMember.userID} 未被禁言`);
					    zz+='<div class="lrlx-box">';
						zz+='<div class="lrlxb-img">';
						zz+='<img src="__PUBLIC__/Home/images/img2.jpg" />';
						zz+='</div>';
						zz+='<div class="lrlxb-mc">'+groupMember.userID+'</div>';
						zz+='<div class="lrlxb-gb">关闭发言</div>';
						zz+='<div class="divclear"></div>';
						zz+='<div class="lrlxb-zt">发言中</div>';
						zz+='</div>';

						bb+='<div class="lrrz-box">';
						bb+='<div class="lrrzb-img">'
						bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
						bb+='</div>';
						bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
						bb+='<div class="lrrzb-jy" onclick="jy()">禁言</div>';
						bb+='<div class="divclear"></div>';
						bb+='</div>';
				    }

				  }
				  $('.lrl-xs').html(zz);
				  $('.lrr-zx').html(bb);
				}).catch(function(imError) {
				    console.warn('getGroupMemberProfile error:', imError);
				});




					let promise = tim.createGroup({
					  type: TIM.TYPES.GRP_AVCHATROOM,
					  name: 'WebSDK',
					  groupID:roomId,
					});
					promise.then(function(imResponse) { // 创建成功
					  console.log(imResponse.data.group); // 创建的群的资料


						let promiser = tim.joinGroup({ 
							groupID: roomId, 
							type: TIM.TYPES.GRP_AVCHATROOM,
						});

						promiser.then(function(imResponse) {
						  switch (imResponse.data.status) {
						    case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
						      break;
						    case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
						      console.log(imResponse.data.group); // 加入的群组资料
						      break;
						    case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
						      break;
						    default:
						      break;
						  }
						}).catch(function(imError){
						  console.warn('joinGroup error:', imError); // 申请加群失败的相关信息
						});


					}).catch(function(imError) {
						console.log(imError.code);
					  // console.warn('createGroup error:', imError); // 创建群组失败的相关信息
					  if(imError.code==10025){


						let promiser = tim.joinGroup({ 
							groupID: roomId, 
							type: TIM.TYPES.GRP_AVCHATROOM,
						});

						promiser.then(function(imResponse) {
						  switch (imResponse.data.status) {
						    case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
						      break;
						    case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
						      console.log(imResponse.data.group); // 加入的群组资料
						      break;
						    case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
						      break;
						    default:
						      break;
						  }
						}).catch(function(imError){
						  console.warn('joinGroup error:', imError); // 申请加群失败的相关信息
						});

					  }
					});




                });
            }

        }
    }).catch(function (imError) {
        console.warn('login error:', imError); // 登录失败的相关信息
    });






});


	        //发消息
        function sendMsg() {
        	var content=$("input[name='xx']").val();
    	    tim.on(TIM.EVENT.SDK_READY, function (event) {
                console.log("ready成功");
            });
            // 发送文本消息，Web 端与小程序端相同
            // 1. 创建消息实例，接口返回的实例可以上屏
            let message = tim.createTextMessage({
                to: roomId,
                conversationType: TIM.TYPES.CONV_GROUP,
                // 消息优先级，用于群聊（v2.4.2起支持）。如果某个群的消息超过了频率限制，后台会优先下发高优先级的消息，详细请参考：https://cloud.tencent.com/document/product/269/3663#.E6.B6.88.E6.81.AF.E4.BC.98.E5.85.88.E7.BA.A7.E4.B8.8E.E9.A2.91.E7.8E.87.E6.8E.A7.E5.88.B6)
                // 支持的枚举值：TIM.TYPES.MSG_PRIORITY_HIGH, TIM.TYPES.MSG_PRIORITY_NORMAL（默认）, TIM.TYPES.MSG_PRIORITY_LOW, TIM.TYPES.MSG_PRIORITY_LOWEST
                // priority: TIM.TYPES.MSG_PRIORITY_NORMAL,
                payload: {
                    text: content
                }
            });
            // 2. 发送消息
            tim.sendMessage(message).then(function (imResponse) {
                // 发送成功
                console.log('发送消息：' + imResponse.data.message.payload.text)
	            var hh='<div class="lrrl-nr"><span style="color:#299cfe;">'+userId+'：</span>'+content+'</div>';
	        	// $('.lrr-lt').append(event.data[0].from + '：' + event.data[0].payload.text);
	        	$("input[name='xx']").val('');
	        	$('.lrr-lt').append(hh);

	        	
            }).catch(function (imError) {
                // 发送失败
                console.warn('sendMessage error:', imError);
            });
        }



       function startLive() {
            // 1、创建 Pusher（推流）对象
            // let pusher = TWebLive.createPusher({userID: userId}); //在前面声明了pusher
            // console.log(pusher);return false;
            // 2、设置渲染界面，且从麦克风采集音频，从摄像头采集视频（默认720p）
            pusher.setRenderView({
                elementID: 'pusherView',
                audio: true,
                video: true
            }).then(() => {
                // 3、填入 sdkappid roomid 等信息，推流
                // url 必须以 `room://` 开头
                let url = `room://sdkappid=` + SDKAppId + `&roomid=` + roomId + `&userid=` + userId + `&usersig=` + userSig + `&livedomainname={$liveDomainName}&streamid={$streamid}`;
                // console.log(pusher.startPush(url));return false;
                pusher.startPush(url).then(() => {
                    console.log('pusher | startPush | ok');
                });
            }).catch(error => {
                console.error('pusher | setRenderView | failed', error);
            });
        }

        function startShare() {
            if (!TRTC.isScreenShareSupported()) {
                layer.msg('当前浏览器不支持屏幕分享');
                return;
            }

            //step1：创建屏幕分享客户端
            shareClient = TRTC.createClient({
                mode: 'rtc',
                sdkAppId: SDKAppId,
                userId: userId,
                userSig: userSig
            });

            //step2：创建屏幕分享流
            // 仅采集屏幕分享视频流
            // shareStream = TRTC.createStream({ audio: false, screen: true, userId });
            // 采集麦克风及屏幕分享视频流
            shareStream = TRTC.createStream({audio: true, screen: true});
            // 采集系统音频及屏幕分享视频流
            // const shareStream = TRTC.createStream({ screenAudio: true, screen: true });
            try {
                async function start() {
                    //step3：初始化屏幕分享流
                    await shareStream.initialize();

                    //step4：屏幕分享客户端进房
                    await shareClient.join({roomId});

                    //step5：屏幕分享客户端发布屏幕分享流
                    await shareClient.publish(shareStream);

                    // 当用户通过浏览器自带的按钮停止屏幕分享时，会监听到 screen-sharing-stopped 事件
                    shareStream.on('screen-sharing-stopped', event => {
                        console.log('share stream video track ended');
                        shareClient.leave();
                    });
                }

                start();
            } catch (e) {
                // 当屏幕分享流初始化失败时, 提醒用户并停止后续进房发布流程
                switch (e.name) {
                    case 'NotReadableError':
                        // 提醒用户确保系统允许当前浏览器获取屏幕内容
                        return;
                    case 'NotAllowedError':
                        if (e.message === 'Permission denied by system') {
                            // 提醒用户确保系统允许当前浏览器获取屏幕内容
                        } else {
                            // 用户拒绝/取消屏幕分享
                        }
                        return;
                    default:
                        // 初始化屏幕分享流时遇到了未知错误，提醒用户重试
                        return;
                }
            }
            // audio 与 screenAudio 属性不能同时设为true, 关于screenAudio更多信息会在本文第五部分介绍。
            shareStream.setScreenProfile('1080p_2');
        }

        function stopShare() {
            async function stop() {
                // 屏幕分享客户端停止推流
                await shareClient.unpublish(shareStream).then(() => {
                    // 取消发布本地流成功

                    // 关闭屏幕分享流
                    shareStream.close();
                });

                console.log('share stream video track ended');
                shareClient.leave();
            }

            stop();
        }
        //聊天
        $("#chat").click(function(){
        	$('.lrr-zx').hide();
        	$('.zx').removeClass('lrrt-btn-on');
        	$('.lt').addClass('lrrt-btn-on');
        	$('.lrr-lt').show();

        })
        //在线
        $("#online").click(function(){
        	$('.lrr-zx').show();
        	$('.zx').addClass('lrrt-btn-on');
        	$('.lrr-lt').hide();
        	$('.lt').removeClass('lrrt-btn-on');
        })

        function jy(){
	    	let promise = tim.setGroupMemberMuteTime({
			  groupID: roomId,
			  userID: 'Dava',
			  muteTime: 600// 禁言10分钟；设为0，则表示取消禁言
			});
			promise.then(function(imResponse) {
			  console.log(imResponse.data.group); // 修改后的群资料
			  console.log(imResponse.data.member); // 修改后的群成员资料
			}).catch(function(imError) {
			  console.warn('setGroupMemberMuteTime error:', imError); // 禁言失败的相关信息
			});


			let promisey = tim.getGroupMemberList({ groupID:roomId, count: 30, offset:0 }); // 从0开始拉取30个群成员   只拉取一次，不知道为什么没有更新，再加载一遍会更新
			let promisey2 = tim.getGroupMemberList({ groupID:roomId, count: 30, offset:0 });
			promisey2.then(function(imResponse) {
			  console.log(imResponse.data.memberList); // 群成员列表
			  var bb=''
			  for (let groupMember of imResponse.data.memberList) {

			    if (groupMember.muteUntil * 1000  > Date.now()) {
			      console.log(`${groupMember.userID} 禁言中`);

					bb+='<div class="lrrz-box">';
					bb+='<div class="lrrzb-img">'
					bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
					bb+='</div>';
					bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
					bb+='<div class="lrrzb-qx" onclick="qxjy()">取消禁言</div>';
					bb+='<div class="divclear"></div>';
					bb+='</div>';
			    } else {
			      console.log(`${groupMember.userID} 未被禁言`);

					bb+='<div class="lrrz-box">';
					bb+='<div class="lrrzb-img">'
					bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
					bb+='</div>';
					bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
					bb+='<div class="lrrzb-jy" onclick="jy()">禁言</div>';
					bb+='<div class="divclear"></div>';
					bb+='</div>';
			    }

			  }
			  $('.lrr-zx').html(bb);
			}).catch(function(imError) {
			    console.warn('getGroupMemberProfile error:', imError);
			});




        }
        function qxjy(){
	    	let promise = tim.setGroupMemberMuteTime({
			  groupID: roomId,
			  userID: 'Dava',
			  muteTime: 0 // 禁言10分钟；设为0，则表示取消禁言
			});
			promise.then(function(imResponse) {
			  console.log(imResponse.data.group); // 修改后的群资料
			  console.log(imResponse.data.member); // 修改后的群成员资料
			}).catch(function(imError) {
			  console.warn('setGroupMemberMuteTime error:', imError); // 禁言失败的相关信息
			});
			let promisey = tim.getGroupMemberList({ groupID:roomId, count: 30, offset:0 }); // 从0开始拉取30个群成员
			let promisey3 = tim.getGroupMemberList({ groupID:roomId, count: 30, offset:0 });
			promisey3.then(function(imResponse) {
			  console.log(imResponse.data.memberList); // 群成员列表
			  var bb=''
			  for (let groupMember of imResponse.data.memberList) {

			    if (groupMember.muteUntil * 1000 > Date.now()) {
			      console.log(`${groupMember.userID} 禁言中`);

					bb+='<div class="lrrz-box">';
					bb+='<div class="lrrzb-img">'
					bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
					bb+='</div>';
					bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
					bb+='<div class="lrrzb-qx" onclick="qxjy()">取消禁言</div>';
					bb+='<div class="divclear"></div>';
					bb+='</div>';
			    } else {
			      console.log(`${groupMember.userID} 未被禁言`);

					bb+='<div class="lrrz-box">';
					bb+='<div class="lrrzb-img">'
					bb+='<img src="__PUBLIC__/Home/images/imgTX.jpg">'
					bb+='</div>';
					bb+='<div class="lrrzb-mz">'+groupMember.userID+'</div>';
					bb+='<div class="lrrzb-jy" onclick="jy()">禁言</div>';
					bb+='<div class="divclear"></div>';
					bb+='</div>';
			    }

			  }
			  $('.lrr-zx').html(bb);
			}).catch(function(imError) {
			    console.warn('getGroupMemberProfile error:', imError);
			});
        }



	 // 打开摄像头
	function startCamera() {
	  pusher.startCamera().then(() => {
	    isStartCamera = false
	  }).catch(() => {})
	}
	// 关闭摄像头
	function stopCamera() {
	  pusher.stopCamera().then(() => {
	    isStartCamera = true
	  }).catch(() => {})
	}
	// 打开麦克风
	function startMicrophone() {
	  pusher.startMicrophone().then(() => {
	    isMute = false
	  }).catch(() => {})
	}
	// 关闭麦克风
	function stopMicrophone() {
	  pusher.stopMicrophone().then(() => {
	    isMute = true
	  }).catch(() => {})
	}

</script>